<template>
  <div class="login-wrap">
    <div class="drag-header"></div>
    <div class="drag-header-mini"></div>
    <div class="drag-header-mini" style="top: 48px"></div>
    <div class="drag-header-mini" style="width: 24px; height: 72px; right: 0"></div>
    <div class="login-wrap-left">
      <div class="title">
        <img src="@/assets/icons/logo-white.png" alt="" class="logo" />
        <div class="logo-text">{{ websiteConfig.title }}</div>
      </div>
      <div class="text-wrap">
        <div class="big-text">欢迎登录<br />{{ websiteConfig.title }}</div>
        <div class="sub-text">陪你写好每一笔</div>
      </div>
    </div>
    <div class="login-wrap-right">
      <div class="tool-wrap">
        <ApOnlineTag />
        <img
          src="@/assets/icons/tool-close.png"
          alt="关闭"
          class="tool-btn"
          @click="ipcSetWindowSize({ type: 'close' })"
        />
      </div>
      <div class="tab-wrap">
        <div class="login-tab">
          <div
            class="tab-item"
            :class="tabType === 'password' ? 'active' : ''"
            @click="tabType = 'password'"
            >密码登录</div
          >
          <div
            class="tab-item"
            :class="tabType === 'code' ? 'active' : ''"
            @click="tabType = 'code'"
            >扫码登录</div
          >
        </div>
        <pwdLoginForm v-if="tabType === 'password'" />
        <codeLoginForm v-if="tabType === 'code'" />
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ref, onBeforeMount } from 'vue';
  import { getApIp } from '@/api/base';
  import { websiteConfig } from '@/config/website.config';
  import { useCourse } from '@/store/modules/course';
  import { ipcSetWindowSize, startJavaServer, ipcGetRootDir } from '@/utils/ipcRenderer';
  import ApOnlineTag from '@/views/components/ApOnlineTag/index.vue';
  import pwdLoginForm from './components/pwdLoginForm.vue';
  import codeLoginForm from './components/codeLoginForm.vue';

  onBeforeMount(() => {
    getApIp().then((res) => {
      useCourse().setApId(res[0]);
    });
    ipcSetWindowSize({ width: 890, height: 530 });
    ipcGetRootDir()
    startJavaServer();
  });
  const tabType = ref('password');
</script>

<style lang="less" scoped>
  .login-wrap {
    width: 890px;
    height: 530px;
    display: flex;
    margin: 0 auto;
    position: relative;

    border-radius: 24px;
    overflow: hidden;
    .drag-header {
      height: 72px;
      position: absolute;
      left: 0;
      right: 130px;
      top: 0;
      z-index: 1;
      -webkit-app-region: drag;
    }
    .drag-header-mini {
      width: 130px;
      height: 24px;
      position: absolute;
      right: 0;
      top: 0;
      z-index: 1;
      -webkit-app-region: drag;
    }
    .login-wrap-left {
      width: 400px;
      height: 530px;
      background: url('@/assets/images/login-wrap-left.png') center center no-repeat;
      background-size: 400px 530px;
      color: #fff;
      padding: 24px;
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .title {
        display: flex;
        align-items: center;
        font-size: 18px;
        position: absolute;
        top: 24px;
        left: 24px;
        height: 28px;
        .logo {
          width: 24px;
          height: 24px;
          margin-right: 2px;
        }
      }
      .text-wrap {
        .big-text {
          font-size: 36px;
        }
        .sub-text {
          font-size: 18px;
          opacity: 0.8;
        }
      }
    }
    .login-wrap-right {
      width: 490px;
      height: 530px;
      background-color: #fdf9f9;
      position: relative;
      .tool-wrap {
        position: absolute;
        right: 24px;
        top: 24px;
        display: flex;
        z-index: 3;

        .tool-btn {
          cursor: pointer;
          width: 24px;
          height: 24px;
          margin-left: 12px;
        }
      }
      .tab-wrap {
        width: 288px;
        margin: 100px auto 0;
      }
      .login-tab {
        display: flex;
        justify-content: center;
        margin-bottom: 32px;
        .tab-item {
          font-size: 24px;
          margin: 0 12px;
          color: #9ba2aa;
          position: relative;
          cursor: pointer;
          &.active {
            color: #2d3441;
            &::after {
              content: '';
              display: block;
              width: 36px;
              height: 4px;
              border-radius: 2px;
              background-color: #eb6100;
              position: absolute;
              left: 50%;
              margin-left: -18px;
              bottom: -4px;
            }
          }
        }
      }
    }
  }

</style>
